package org.xinjiang.data.migration.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
import org.xinjiang.data.migration.common.annotations.Describe;

/**
 * 是否枚举
 *
 * @author wenjie
 * @date 2019/08/06
 */
@Describe("是否枚举")
public enum YesNoEnum implements BaseEnum {

    /**
     * 否, 是
     */
    NO("0", "否"), YES("1", "是");

    @Getter(onMethod_ = {@JsonValue})
    private final String code;

    @Getter
    private final String describe;

    YesNoEnum(String code, String describe) {
        this.code = code;
        this.describe = describe;
    }

    public static YesNoEnum of(boolean b) {
        return b ? YES : NO;
    }

    @JsonCreator
    public static YesNoEnum of(String code) {
        return BaseEnum.of(YesNoEnum.class, code);
    }

    public boolean as() {
        return this.equals(YES);
    }

}
